import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: import('../views/page/ExploreView.vue'),
      meta: {
        title: '首页'
      }
    },
    {
      path: '/creative',
      name: 'creative',
      component: import('../views/page/CreativeView.vue'),
      meta: {
        title: '创作中心'
      }
    },
    {
      path: '/search',
      name: 'search',
      component: import('../views/page/GlobalSearch.vue'),
      meta: {
        title: '搜索'
      }
    },
    {
      path: '/video/:workId',
      name: 'video',
      component: import('../views/page/Video.vue'),
      meta: {
        title: '视频播放'
      }
    },
    {
      path: '/collect',
      name: 'collect',
      component: import('../views/page/VideoCollect.vue'),
      meta: {
        title: '视频收藏'
      }
    },
    {
      path: '/profile/:userId',
      name: 'profile',
      component: import('../views/page/UserProfile.vue'),
      meta: {
        title: '个人主页'
      }
    }
  ]
})

// 全局前置守卫
router.beforeEach((to, from, next) => {
  // 如果路由配置中有 meta.title，则设置页面标题
  if (to.meta.title) {
    document.title = to.meta.title + ' - 分布式视频应用';
  }
  next();
});

export default router
